/*
 * @file gkt_widget_list.h
 */

#ifndef GKT_WIDGET_LIST_H
#define GKT_WIDGET_LIST_H

#include "gkt_types.h"

#ifdef __cplusplus
extern "C" {
#endif

#if defined(GKT_CONFIG_SCREEN_ENABLE) && GKT_CONFIG_SCREEN_ENABLE

typedef struct _gkt_widget_list_item {
	uint32_t	text;	/* id or pointer of text or voice */
	uint32_t	data;	/* child_window_id, user_id, ... */
} gkt_widget_list_item_s;

#define GKT_WIDGET_LIST_STATIC_ITEM(_text, _data)	\
	{	\
		.text	= (uint32_t)(_text),	\
		.data	= _data,	\
	}

/* list extend attr */
typedef struct _gkt_widget_list_attr {
	uint16_t	item_height;
	uint16_t	item_nums;
	const gkt_widget_list_item_s	*const_items;
} gkt_widget_list_attr_s;

#define GKT_WIDGET_LIST_STATIC_ATTR(_item_height, _item_nums, _items)	\
	{	\
		.item_height	= (uint16_t)(_item_height),	\
		.item_nums	= (uint16_t)(_item_nums),	\
		.const_items	= (const gkt_widget_list_item_s *)(_items),	\
	}

#define GKT_WIDGET_LIST_DESC(_flags, \
			_font_size, _fg_color, _bg_color, \
			_x, _y, _w, _h, attr)	\
	GKT_WIDGET_DESC(LIST, (_flags) | GKT_WIDGET_F_FOCUSABLE, \
			_font_size, _fg_color, _bg_color,	\
			_x, _y, _w, _h, attr)

int gkt_widget_list_event_handler(gkt_widget_s *widget, 
					uint32_t major_type, uint32_t minor_type, 
					uint32_t data);

uint32_t gkt_widget_list_get_item_nums(
				gkt_widget_id_t widget_id);

uint32_t gkt_widget_list_get_item_data(
				gkt_widget_id_t widget_id, uint32_t item_index);

int gkt_widget_list_add_item(
				gkt_widget_id_t widget_id,
				const gkt_widget_list_item_s *item);

int gkt_widget_list_delete_item(
				gkt_widget_id_t widget_id, 
				uint32_t item_index);

void gkt_widget_list_set_focus(gkt_widget_id_t widget_id, 
				uint32_t item_index);

void gkt_widget_list_set_focus_by_data(gkt_widget_id_t widget_id,
			uint32_t item_data);
#else

typedef struct _gkt_widget_list_item {
	uint32_t	voice;	/* id or pointer of voice */
	uint32_t	data;	/* child_window_id, user_id, ... */
} gkt_widget_list_item_s;

#define GKT_WIDGET_LIST_STATIC_ITEM(_voice, _data)	\
	{	\
		.voice	= (uint32_t)(_voice),	\
		.data	= _data,	\
	}

/* list extend attr */
typedef struct _gkt_widget_list_attr {
	uint32_t	item_nums;
	const gkt_widget_list_item_s	*const_items;
} gkt_widget_list_attr_s;

#define GKT_WIDGET_LIST_STATIC_ATTR(_item_nums, _items)	\
	{	\
		.item_nums	= (uint16_t)(_item_nums),	\
		.const_items	= (const gkt_widget_list_item_s *)(_items),	\
	}

#define GKT_WIDGET_LIST_DESC(_flags, attr)	\
	GKT_WIDGET_DESC(LIST, (_flags) | GKT_WIDGET_F_FOCUSABLE, attr)

int gkt_widget_list_event_handler(gkt_widget_s *widget, 
					uint32_t major_type, uint32_t minor_type, 
					uint32_t data);

uint32_t gkt_widget_list_get_item_nums(
				gkt_widget_id_t widget_id);

const gkt_widget_list_item_s *gkt_widget_list_get_item(
				gkt_widget_id_t widget_id, uint32_t item_index);

int gkt_widget_list_add_item(gkt_widget_id_t widget_id,
				const gkt_widget_list_item_s *item);

uint32_t gkt_widget_list_get_item_data(
				gkt_widget_id_t widget_id, uint32_t item_index);
#endif

#ifdef __cplusplus
}
#endif

#endif	/* GKT_WIDGET_LIST_H */

